package com.atguigu.dwm.model.controller;

import com.atguigu.dwm.common.bean.QueryInfo;
import com.atguigu.dwm.common.bean.Result;
import com.atguigu.dwm.model.bean.DmDimension;
import com.atguigu.dwm.model.service.DmDimensionService;
import com.atguigu.dwm.plan.bean.DpBusiProcess;
import com.atguigu.dwm.plan.service.DpBusiProcessService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 维度 前端控制器
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/data-model/dim")
public class DmDimensionController {

    @Autowired
    DmDimensionService dmDimensionService ;



    @GetMapping("/list")
    public Result getList(QueryInfo queryInfo){  //

        List<DmDimension> list = dmDimensionService.getQueryList(queryInfo);
        Integer total = dmDimensionService.getQueryTotal(queryInfo);
        return Result.ok(list,total);

    }

    @PostMapping("/detail")
    public Result save(@RequestBody DmDimension dmDimension){
        dmDimension.setLastUpdateTime(new Date());
        dmDimension.setLastUpdateUserId(9999L);
        dmDimensionService.saveOrUpdate(dmDimension);//保存后 会把主键补充在id上
        return Result.ok(dmDimension);
    }

    @GetMapping("/detail/{id}")
    public Result getDetail(@PathVariable("id") Long id){
        return Result.ok(dmDimensionService.getById(id));
    }

    @GetMapping("/options")
    public Result getOptions(@RequestParam(value = "modelId",required = false) Long modelId){
        List<Map<String, Object>> mapList = dmDimensionService.listMaps(new QueryWrapper<DmDimension>()
                .eq(modelId!=null , "model_id", modelId)
                .select("id", "name_chn as name", "name_eng as nameEng").eq("is_deleted", "0"));
        return Result.ok(mapList);
    }

}
